// // --------------------------------------------------------------------------------------------------------------------
// // <copyright file="RunSettings.cs" company="Collaboris">
// //   Copyright Collaboris
// // </copyright>
// // <summary>
// //   
// // </summary>
// // --------------------------------------------------------------------------------------------------------------------

namespace Collaboris.ShareTest.Core
{
    #region

    using System;
    using System.Configuration;

    #endregion

    /// <summary>
    /// 	The global.
    /// </summary>
    public static class RunSettings
    {
        #region Constants and Fields

        private static string autoItDirectory;

        private static string centralAdminSiteUrl;

        private static TimeSpan? driverTimeout;

        private static int operationRetryInterval;

        private static int operationRetryTimes;

        /// <summary>
        /// 	The site url.
        /// </summary>
        private static string siteUrl;

        private static string webBrowser;

        private static string workingDirectory;

        private static DateTime? productInstallationDate;

        #endregion

        #region Public Properties

        public static bool AuthenticatedToCloudShare { get; set; }

        /// <summary>
        /// 	Gets or sets AutoItDirectory.
        /// </summary>
        public static string AutoItDirectory
        {
            get
            {
                if (string.IsNullOrEmpty(autoItDirectory))
                {
                    autoItDirectory = ConfigurationManager.AppSettings["AutoItDirectory"];
                }

                return autoItDirectory;
            }

            set
            {
                centralAdminSiteUrl = value;
            }
        }

        public static string CentralAdminSiteUrl
        {
            get
            {
                if (string.IsNullOrEmpty(centralAdminSiteUrl))
                {
                    centralAdminSiteUrl = ConfigurationManager.AppSettings["CentralAdminSiteUrl"];
                }

                return centralAdminSiteUrl;
            }

            set
            {
                centralAdminSiteUrl = value;
            }
        }

        /// <summary>
        /// 	Gets or sets DriverTimeout.
        /// </summary>
        public static TimeSpan? DriverTimeout
        {
            get
            {
                if (!driverTimeout.HasValue)
                {
                    string millseconds = ConfigurationManager.AppSettings["DriverTimeout"];
                    driverTimeout = TimeSpan.FromMilliseconds(Convert.ToDouble(millseconds));
                }

                return driverTimeout;
            }

            set
            {
                driverTimeout = value;
            }
        }

        // static...

        /// <summary>
        /// 	Gets or sets OperationRetryInterval.
        /// </summary>
        public static int OperationRetryInterval
        {
            get
            {
                if (operationRetryInterval < 1)
                {
                    operationRetryInterval = Convert.ToInt32(ConfigurationManager.AppSettings["OperationRetryInterval"]);
                }
                return operationRetryInterval;
            }

            set
            {
                operationRetryInterval = value;
            }
        }

        public static DateTime? ProductInstallationDate
        {
            get
            {
                if (!productInstallationDate.HasValue)
                {
                    productInstallationDate = DateTime.Parse(ConfigurationManager.AppSettings["ProductInstallationDate"]);
                }
                return productInstallationDate.Value;
            }

            set
            {
                productInstallationDate = value;
            }
        }

        /// <summary>
        /// 	Gets or sets OperationRetryTimes.
        /// </summary>
        public static int OperationRetryTimes
        {
            get
            {
                if (operationRetryTimes < 1)
                {
                    operationRetryTimes = Convert.ToInt32(ConfigurationManager.AppSettings["OperationRetryTimes"]);
                }
                return operationRetryTimes;
            }

            set
            {
                operationRetryTimes = value;
            }
        }

        /// <summary>
        /// 	Gets or sets a value indicating whether SiteInCloudShare.
        /// </summary>
        public static bool SiteInCloudShare
        {
            get
            {
                return Convert.ToBoolean(ConfigurationManager.AppSettings["SiteInCloudShare"]);
            }
        }

        /// <summary>
        /// 	Gets or sets SiteUrl from config
        /// </summary>
        public static string SiteUrl
        {
            get
            {
                if (string.IsNullOrEmpty(siteUrl))
                {
                    siteUrl = ConfigurationManager.AppSettings["SiteUrl"];
                }

                return siteUrl;
            }

            set
            {
                siteUrl = value;
            }
        }

        /// <summary>
        /// 	Gets or sets WebBrowser.
        /// </summary>
        public static string WebBrowser
        {
            get
            {
                if (string.IsNullOrEmpty(webBrowser))
                {
                    webBrowser = ConfigurationManager.AppSettings["WebBrowser"];
                }

                return webBrowser;
            }

            set
            {
                webBrowser = value;
            }
        }

        /// <summary>
        /// 	The working directory.
        /// </summary>
        public static string WorkingDirectory
        {
            get
            {
                if (string.IsNullOrEmpty(workingDirectory))
                {
                    workingDirectory = ConfigurationManager.AppSettings["WorkingDirectory"];
                }

                return workingDirectory;
            }

            set
            {
                workingDirectory = value;
            }
        }

        #endregion
    }
}